package com.quad.innovators.salesease.controller.warehouse;

import com.quad.innovators.salesease.annotation.Log;
import com.quad.innovators.salesease.common.result.Result;
import com.quad.innovators.salesease.constants.SystemConstants;
import com.quad.innovators.salesease.enums.LogModuleEnum;
import com.quad.innovators.salesease.model.form.warehouse.SaleOrderScanForm;
import com.quad.innovators.salesease.model.form.warehouse.VehicleBringScanCodeForm;
import com.quad.innovators.salesease.service.warehouse.SaleOrderScanService;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

/**
 * @author : shanshan.li
 * @createTime : 2025/4/24 10:28
 * @Version : 1.0 
 */
@Tag(name = "19.销售单扫码详情")
@RestController
@RequestMapping(SystemConstants.BACKEND_API + "/sale-order-scan")
@RequiredArgsConstructor
public class SaleOrderScanController {

    private final SaleOrderScanService saleOrderScanService;

    @Operation(summary = "新增扫码信息")
    @PostMapping("")
    @Log(value = "新增扫码信息", module = LogModuleEnum.SALE_RETURN_ORDER)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<?> save(SaleOrderScanForm form) {
        String result = saleOrderScanService.save(form);
        return Result.success(result);
    }

    @Operation(summary = "删除扫码信息")
    @DeleteMapping("/{code}")
    @Log(value = "删除扫码信息", module = LogModuleEnum.SALE_RETURN_ORDER)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<?> delete(@PathVariable("code") String code) {
        boolean result = saleOrderScanService.delete(code);
        return Result.success(result);
    }

    @Operation(summary = "获取扫码列表")
    @GetMapping("/{saleOrderDetailCode}/list")
    @Log(value = "获取扫码列表", module = LogModuleEnum.SALE_RETURN_ORDER)
    // @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<List<SaleOrderScanForm>> getList(@PathVariable("saleOrderDetailCode") String saleOrderDetailCode) {
        return Result.success(saleOrderScanService.getListByVehicleCode(saleOrderDetailCode));
    }
}
